package org.example;

class Solution {
    void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }

    boolean isEven(int v) {
        return v % 2 == 0;
    }

    public int[] sortArrayByParityII(int[] nums) {
        int even = 0;
        int odd = 1;
        while (even < nums.length) {
            if (!isEven(nums[even]))  {
                while (!isEven(nums[odd])) {
                    odd += 2;
                }
                swap(nums, even, odd);
            }
            even += 2;
        }
        return nums;
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}